import time

from selenium.webdriver.common.by import By
from Base.Base import Base
from Page.Boss import Boss


class PayManage(Boss):
    # 支付产品信息
    product_loc = (By.XPATH, '/html/body/div[1]/div[2]/div[2]/div[2]/div[8]/ul/li[1]/div/a')

    # 上架
    audit_loc = (
        By.CSS_SELECTOR,
        '#navTab > div.navTab-panel.tabsPageContent.layoutBox > div:nth-child(2) > div.pageContent.j-resizeGrid > div.grid > div.gridScroller > div > table > tbody > tr:nth-child(1) > td:nth-child(6) > div > a:nth-child(2)')

    # 无支付方式上架
    audit_nopayment_loc = (
    By.XPATH, '/html/body/div[1]/div[3]/div/div[2]/div[7]/div[2]/div[2]/div[2]/div/table/tbody/tr[4]/td[6]/div/a[2]')

    # 取消
    dismiss_loc = (By.XPATH, '/html/body/div[13]/div[1]/div/div[2]/ul/li[2]/a/span')

    # 提示框确认
    confirm_loc = (By.XPATH, '/html/body/div[13]/div[1]/div/div[2]/ul/li[1]/a')

    # 弹出框确认
    confirm2_loc = (By.XPATH, '/html/body/div[13]/div[1]/div/div[2]/ul/li/a/span')

    # 下架
    tekedown_loc = (By.XPATH,'/html/body/div[1]/div[3]/div/div[2]/div[2]/div[2]/div[2]/div[2]/div/table/tbody/tr[1]/td[6]/div/a[2]')

    # 点击支付产品信息
    def payment_order(self):
        self.click(self.product_loc)

    # 点击上架
    def audit(self):
        self.click(self.audit_loc)

    # 点击取消
    def dismiss(self):
        self.click(self.dismiss_loc)

    # 点击提示框确认
    def confirm(self):
        self.click(self.confirm_loc)

    # 点击弹出框确认
    def confirm2(self):
        self.click(self.confirm2_loc)

    # 上架无支付方式
    def no_payment(self):
        self.click(self.audit_nopayment_loc)

    # 点击下架
    def takedown(self):
        self.click(self.tekedown_loc)

    # 用例：支付产品列表正常显示
    def payment_list(self):
        self.pay_manage()
        self.payment_order()

    # 用例：上架支付产品，弹出二次确认提示框
    def audit_alert(self):
        self.payment_order()
        self.audit()

    # 用例：上架支付产品，选择取消，上架失败
    def audit_dismiss(self):
        self.payment_order()
        self.audit()
        time.sleep(1)
        self.dismiss()

    # 用例：上架支付产品，选择确认，上架成功
    def audit_confirm(self):
        self.payment_order()
        self.audit()
        time.sleep(1)
        self.confirm()
        time.sleep(1)
        self.confirm2()

    # 用例：下架支付产品，弹出二次确认提示框
    def takedown_alert(self):
        self.payment_order()
        self.takedown()

    # 用例：下架支付产品，点击确认，下架成功
    def takedown_confirm(self):
        self.payment_order()
        self.takedown()
        time.sleep(1)
        self.confirm()
        time.sleep(1)
        self.confirm2()

    # 用例：下架支付产品，点击取消，下架失败
    def takedown_dismiss(self):
        self.payment_order()
        self.takedown()
        time.sleep(1)
        self.dismiss()


    # 没有设置支付方式无法上架
    def no_payment_audit(self):
        self.payment_order()
        self.no_payment()
